export function checkHttpStatus(res) {
  if (res.status >= 200 && res.status < 300) {
	  return res
  } else {
  	var error = new Error(res.statusText)
  	error.res = res
  	throw error
  }
}

export function parseJSON(res) {
  return res.json()
}

export function postJsonMethod(data) {
  return {
    method: 'post',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(data)
  }
};

export const getMethod = {
  method: 'get',
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json'
  }
};

export function formatDate(date) {
  var d = new Date(date),
    month = '' + (d.getMonth() + 1),
    day = '' + d.getDate(),
    year = d.getFullYear();
 
  if (month.length < 2) month = '0' + month;
  if (day.length < 2) day = '0' + day;
 
  return [year, month, day].join('/');
}

export function transformStr(str) {
  var re=/-(\w)/g;
  return str.replace(re, function($0, $1) {
      return $1.toUpperCase();
  });
}
